package com.scope.customViews;

import android.graphics.Point;
import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

/**
 * Created by Samrith on 10/6/13.
 */
public class CustomView {
    public static final class SizeDegree {
        public static final int UNDEFINED = 0;
        public static final int CUSTOM = 1;
        public static final int EXTRA_SMALL = 4;
        public static final int SMALL = 5;
        public static final int MEDIUM = 9;
        public static final int LARGE = 13;
        public static final int EXTRA_LARGE = 14;
    }

    public static final class Orientation {
        public static final int VERTICAL = 0;
        public static final int HORIZONTAL = 1;
    }

    public static final class Explorer {
        public static final int General = 0;
        public static final int SpecificFolder = 1;
        public static final int FileExplorer = 2;
    }

    public static class StaticMethods {
        public static void ScreenSizeLayout(Window window, Point size) {
            Rect display = new Rect();
            window.getDecorView().getWindowVisibleDisplayFrame(display);

            DisplayMetrics metrics = new DisplayMetrics();
            window.getWindowManager().getDefaultDisplay().getMetrics(metrics);

            size.x = metrics.heightPixels - window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
            size.y = metrics.widthPixels;

            Log.i("LayoutHeight", "height = " + size.x + "; width = " + size.y);
        }

        public static void setAccent(ViewGroup viewGroup, int accent) {
            if (viewGroup == null) return;

            int count = viewGroup.getChildCount();
            for (int i = 0; i < count; i++) {
                try {
                    IAccent target = (IAccent) viewGroup.getChildAt(i);
                    target.setAccent(accent);
                } catch (Exception e) {
                    try {
                        ViewGroup target = (ViewGroup) viewGroup.getChildAt(i);
                        setAccent(target, accent);
                    } catch (Exception ee) {
                    }
                }
            }
        }

        public static void setBackgroundColor(ViewGroup viewGroup, int theme, Class<?>... targetClass) {
            if (viewGroup == null || targetClass.length == 0) return;

            int count = viewGroup.getChildCount();
            for (int i = 0; i < count; i++) {
                for (Class<?> cls : targetClass) {
                    View v = viewGroup.getChildAt(i);
                    if (v.getClass() == cls) {
                        v.setBackgroundColor(theme);
                        break;
                    }
                }
            }
        }
    }

    public static final class FreqLog {
        public static void InitializingViews(Object obj) {
            Log.i(obj.toString(), "Initializing views...");
        }

        public static void InitializedViews(Object obj) {
            Log.i(obj.toString(), "Views are initialized.");
        }

        public static void PositioningViews(Object obj) {
            Log.i(obj.toString(), "Positioning views...");
        }

        public static void PositionedViews(Object obj) {
            Log.i(obj.toString(), "Views are re-positioned.");
        }
    }

    public interface IAccent {
        int getAccent();

        void setAccent(int accent);
    }

    /**
     * DualView is for two same-type view sit on each other
     * New params are set to the Back view
     * toggle() to bring the back view to the front
     *
     * @param <T>
     */
    public interface DualView<T extends View> {
        T getFront();

        T getBack();

        void toggle();
    }
}
